package com.newly.api.business.feign;

import com.newly.common.base.constants.ServerUriConstant;
import com.newly.common.base.entity.R;
import com.newly.common.base.entity.business.Vo.MqttDeviceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Api(tags = "MQTT设备管理")
@FeignClient(path = ServerUriConstant.NEWLY_BUSINESS_MQTT_Device, name = ServerUriConstant.NEWLY_BUSINESS_SERVICE_NAME)
public interface MQTTDeviceClient {

//    @GetMapping("/reConnect")
//    public boolean reConnect(){
//        MqttUtils.reConnect();
//        return MqttUtils.serverIsConnected();
//    }

    @ApiOperation("获取在线网关的productKey")
    @GetMapping("/getLivingGateway")
    R getLivingGateway();

    @ApiOperation("搜索设备")
    @GetMapping("/search")
    R search(@RequestBody MqttDeviceVo data);

    @ApiOperation("添加设备")
    @PostMapping("/add")
    R add(@RequestBody MqttDeviceVo data);

    @ApiOperation("删除设备")
    @PostMapping("/delete")
    R delete(@RequestBody List<String> ids);

    @ApiOperation("删除相机")
    @PostMapping("/deleteCamera")
    R deleteCamera(@RequestBody MqttDeviceVo data,
                   @RequestParam(value = "slot", required = false) int slot,
                   @RequestParam(value = "channelIndex", required = false) int[] channelIndex);

    @ApiOperation("修改设备")
    @PostMapping("/modify")
    R modify(@RequestBody MqttDeviceVo data);

    @ApiOperation("修改网关设备")
    @PostMapping("/modifyGateway")
    R modifyGateway(@RequestBody MqttDeviceVo data);

    @ApiOperation("删除网关设备")
    @PostMapping("/deleteGateway")
    R deleteGateway(@RequestBody List<String> ids);

    @ApiOperation("配置视频设备通道编码")
    @PostMapping("/modifyVideoId")
    R modifyVideoId(@RequestBody MqttDeviceVo data);

    @ApiOperation("列表查询设备信息")
    @GetMapping("/getList")
    R getList(@RequestBody MqttDeviceVo data,
              @RequestParam(value = "slot", required = false) int[] slot);

    @ApiOperation("同步网关设备")
    @PostMapping("/deviceSync")
    R deviceSync(@RequestBody MqttDeviceVo data);

    @ApiOperation("导出设备管理表")
    @GetMapping("/export")
    void export(HttpServletResponse response,
                @RequestParam(value = "keyword", required = false) String keyword,
                @RequestParam(value = "deviceStatus", required = false) Integer deviceStatus,
                @RequestParam(value = "siteId", required = false) Long siteId,
                @RequestParam(value = "type", required = false) Integer type);

    @ApiOperation("列表查询设备信息")
    @GetMapping("/getDeviceList")
    R getDeviceList(@RequestParam(value = "keyword", required = false) String keyword,
                    @RequestParam(value = "deviceStatus", required = false) Integer deviceStatus,
                    @RequestParam(value = "siteId", required = false) Long siteId,
                    @RequestParam(value = "type", required = false) Integer type,
                    @RequestParam(value = "pageNum", required = false) Integer pageNum,
                    @RequestParam(value = "pageSize", required = false) Integer pageSize);

    @ApiOperation("获取设备flv直播地址")
    @GetMapping("/getDeviceFlvUrl")
    R getDeviceFlvUrl(@RequestParam(value = "id", required = true) String id,
                      @RequestParam(value = "type", required = false) String type);

    @ApiOperation("获取设备flv历史视频地址")
    @GetMapping("/getDeviceHistoryFlvUrl")
    R getDeviceHistoryFlvUrl(@RequestParam(value = "date", required = false) String date,
                             @RequestParam(value = "siteId", required = false) String siteId);

    @ApiOperation("获取某个闭区间存在媒体文件的日期")
    @GetMapping("/getDateOfExistenceOfMedia")
    R getDateOfExistenceOfMedia(@RequestParam(value = "siteId", required = false) String siteId,
                                @RequestParam(value = "startDate", required = false) String startDate,
                                @RequestParam(value = "endDate", required = false) String endDate);

    @ApiOperation("查询设备树状图")
    @GetMapping("/getDeviceTree")
    R getDeviceTree(@RequestParam(value = "keyword", required = false) String keyword);

    @ApiOperation("通过id查询设备")
    @GetMapping("/queryByIdsInAuth")
    R queryByIdsInAuth(@NotEmpty(message = "deviceIds can't be empty")
                       @RequestParam("deviceIds") List<String> deviceIds);
}
